|
1 | 1 | from kitsune.products.tests import ProductFactory, TopicFactory
|
2 |
| -from kitsune.products.utils import get_taxonomy |
| 2 | +from kitsune.products.utils import get_products, get_taxonomy |
3 | 3 | from kitsune.sumo.tests import TestCase
|
4 | 4 |
|
5 | 5 |
|
@@ -408,3 +408,65 @@ def test_specific_product_with_metadata(self):
|
408 | 408 | ),
|
409 | 409 | expected,
|
410 | 410 | )
|
| 411 | + |
| 412 | + |
| 413 | +class GetProductsTests(TestCase): |
| 414 | + |
| 415 | + def setUp(self): |
| 416 | + ProductFactory( |
| 417 | + title="product1", description="All about product1...", display_order=1, slug="p1" |
| 418 | + ) |
| 419 | + ProductFactory( |
| 420 | + title="product2", description="All about product2...", display_order=2, slug="p2" |
| 421 | + ) |
| 422 | + ProductFactory( |
| 423 | + title="product3", |
| 424 | + description="All about product3...", |
| 425 | + display_order=3, |
| 426 | + slug="mozilla-account", |
| 427 | + visible=False, |
| 428 | + ) |
| 429 | + ProductFactory( |
| 430 | + title="product4", |
| 431 | + description="All about product4...", |
| 432 | + display_order=4, |
| 433 | + slug="p4", |
| 434 | + visible=False, |
| 435 | + ) |
| 436 | + ProductFactory( |
| 437 | + title="product5", |
| 438 | + description="All about product5...", |
| 439 | + display_order=5, |
| 440 | + slug="p5", |
| 441 | + is_archived=True, |
| 442 | + ) |
| 443 | + |
| 444 | + def test_get_products(self): |
| 445 | + expected = """products: |
| 446 | +- title: product1 |
| 447 | + description: All about product1... |
| 448 | +- title: product2 |
| 449 | + description: All about product2... |
| 450 | +- title: product3 |
| 451 | + description: All about product3... |
| 452 | +""" |
| 453 | + self.assertEqual(get_products(), expected) |
| 454 | + |
| 455 | + def test_get_products_as_json(self): |
| 456 | + expected = """{ |
| 457 | + "products": [ |
| 458 | + { |
| 459 | + "title": "product1", |
| 460 | + "description": "All about product1..." |
| 461 | + }, |
| 462 | + { |
| 463 | + "title": "product2", |
| 464 | + "description": "All about product2..." |
| 465 | + }, |
| 466 | + { |
| 467 | + "title": "product3", |
| 468 | + "description": "All about product3..." |
| 469 | + } |
| 470 | + ] |
| 471 | +}""" |
| 472 | + self.assertEqual(get_products(output_format="JSON"), expected) |
0 commit comments